package cn.com.ninng;

/**
 * 删除有序数组中的重复项
 * @author liulekang
 * @createdate 2021/7/28
 */
public class Problem26 {

    public static void main(String[] args) {

        System.out.println(removeDuplicates(new int[]{1,1,2}));

    }


    public static int removeDuplicates(int[] nums) {

        //双指针法，不重复的元素覆盖重复的元素
        int j = 0;
        for (int i = 1; i < nums.length; i++) {
            if (nums[i] != nums[j]) {
                nums[j+1] = nums[i];
                j++;
            }
        }
        return j+1;
    }


}
